package com.zhkj.txg.module.mine.vm

import android.app.Application
import androidx.lifecycle.MutableLiveData
import com.zhkj.lib.base.BaseViewModel
import com.zhkj.lib.base.LogoutEvent
import com.zhkj.lib.http.BaseResponse
import com.zhkj.lib.http.HttpResponse
import com.zhkj.lib.http.ViewModelSubscribeListener
import com.zhkj.lib.utils.AccountManager
import com.zhkj.lib.utils.RxBus
import com.zhkj.txg.module.mine.entity.AboutUsResponse
import com.zhkj.txg.module.mine.entity.GuideListResponse
import com.zhkj.txg.module.mine.entity.VersionResponse
import com.zhkj.txg.module.mine.model.MineManager

class SettingViewModel(application: Application) : BaseViewModel(application) {
    private val manager = MineManager()
    val logoutLiveData = MutableLiveData<HttpResponse<BaseResponse>>()
    val aboutUsLiveData = MutableLiveData<HttpResponse<AboutUsResponse>>()
    val guideListLiveData = MutableLiveData<HttpResponse<GuideListResponse>>()
    val versionLiveData = MutableLiveData<HttpResponse<VersionResponse>>()

    fun logout(token: String) {
        val listener = object : ViewModelSubscribeListener<BaseResponse>(logoutLiveData) {
            override fun onSuccess(resp: BaseResponse) {
                AccountManager.clearUserInfo()
                RxBus.post(LogoutEvent())
                super.onSuccess(resp)
            }
        }
        val logout = manager.logout(token, listener)
        dispose.add(logout)
    }


    fun aboutUs() {
        val aboutUs = manager.aboutUs(ViewModelSubscribeListener(aboutUsLiveData))
        dispose.add(aboutUs)
    }

    fun guideList() {
        val guideList = manager.guideList(ViewModelSubscribeListener(guideListLiveData))
        dispose.add(guideList)
    }


    fun getVersion() {
        val guideList = manager.getVersion(ViewModelSubscribeListener(versionLiveData))
        dispose.add(guideList)
    }
}